Skip to content

feat(db): add release_level alongside release_status (BDMS-1382) - #1052

Merged
likithabommasani21 merged 7 commits into
stagingfrom
BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status
Nov 23, 2026
Merged

likithabommasani21 merged 7 commits into
stagingfrom
BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status

Conversation

@likithabommasani21

@likithabommasani21 likithabommasani21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

  • ReleaseMixin gives every record one release_status column that's being asked two unrelated questions at once: who may see it, and how far along it is in review. Per docs/release-level-and-data-maturity-vocabulary.md, this is step one of splitting that into two independent fields: adding release_level alongside the existing column.

How

Implementation summary: the following was changed / added / removed:

  • Added a release_level lexicon category (pending/private/public) to core/lexicon.json, tagging the existing public/private terms and adding the new pending term. Added ReleaseLevel to core/enums.py.
  • Added release_level to db/base.py's ReleaseMixin, defaulting new rows to pending.
  • Added migration 73d27e78571a: adds release_level to all 35 ReleaseMixin tables and backfills it by exact value name only (public→public, private→private, draft/provisional→pending) -- raises rather than guessing if any other value shows up, since published/final/archived are expected to have zero rows anywhere.
  • Also adds release_level to the _version shadow table of the 7 __versioned__ (sqlalchemy_continuum) tables among those 35, which must mirror the live table's columns or every write to them fails.
  • release_status is not dropped in this PR -- kept for now, consumers migrated and the column dropped in later follow-ups.

Author Checklist

  • Changes are limited to the intended scope.
  • [N/A] Tests were added or updated where appropriate.
  • Relevant tests and lint checks pass.
  • No secrets, credentials, or sensitive data were publicly exposed.
  • [N/A] Documentation was updated where necessary.

Reviewer Checklist

  • Confirm draft/provisional→pending is the right backfill, and that raising on any other value (rather than defaulting it) is the right call.
  • Confirm provisional→pending for transducer_observation/transducer_observation_block specifically -- this is still an assumption pending sign-off from whoever owns the hydrograph correction workflow, not a final decision.
  • Confirm keeping release_status in place for now (two-step rollout) rather than dropping it in this same PR.

Notes

Any special considerations, known limitations, risks, workarounds, or follow-up work to note?

  • This PR only adds release_level and backfills it -- updating the ~38 consumer files, the two materialized chemistry views, and dropping release_status are separate follow-up steps, not part of this PR.

  • Verified: migration applies and reverts cleanly on a fresh local database; full test suite passes (1299 passed, 0 failures, excluding modules with a pre-existing unrelated missing-dependency issue in this environment).

  • Two BDD scenarios in tests/features/ogc-cleanup-sprint1.feature fail against this branch: "Sprint 1 migration restricts all ogc_* views to public records" and "The 4 already-consistent layers are unaffected by the migration."

  • Root cause: these scenarios deliberately rewind the real database schema to an old revision (PRE_A1_REVISION, well before this change) to test an old migration in isolation, then seed test data using the current SQLAlchemy ORM model classes. Since release_level is now a mapped column on ReleaseMixin, every model using it (Group, Location, etc.) always includes release_level in its generated INSERT statement -- regardless of whether it's set, and regardless of any default (client-side, server-side, or none at all; all three were tried and all fail the same way). Against the rewound schema, that column doesn't exist yet, so the insert fails with column "release_level" of relation "group" does not exist.

  • I think this needs a fix on the test side (e.g., _seed_all in tests/features/steps/ogc-cleanup-sprint1.py seeding via raw SQL instead of the ORM for these two scenarios specifically) -- not resolved in this PR. @ksmuczynski @jirhiker any thoughts on this ?

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

❌ 43.17% total — gate is 75%.

Coverage for the Python files changed in this PR
Name Stmts Miss Cover Missing
core/enums.py 63 0 100%
db/base.py 55 2 96% 174, 191
TOTAL 118 2 98%

@likithabommasani21
likithabommasani21 force-pushed the BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status branch from e0ce2bf to ed4e2f4 Compare November 13, 2026 18:01
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

✅ 82.03% total — gate is 75%.

Coverage for the Python files changed in this PR
Name Stmts Miss Cover Missing
core/enums.py 63 0 100%
db/base.py 55 2 96% 174, 191
TOTAL 118 2 98%

@likithabommasani21
likithabommasani21 marked this pull request as draft November 13, 2026 18:04
@likithabommasani21
likithabommasani21 requested review from jacob-a-brown, jirhiker and ksmuczynski and removed request for ksmuczynski November 14, 2026 00:00
@likithabommasani21
likithabommasani21 marked this pull request as ready for review November 14, 2026 00:00
for table in TABLES:
op.add_column(
table,
sa.Column("release_level", sa.String(length=100), nullable=True),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this should be nullable. The lexicon_term column in the mixin is a foreign key, which can't be nullable (I think?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it NOT NULL — agreed it shouldn't ever be empty. One small correction though: I think FKs actually can be nullable (release_status already is, same pattern), just added it as nullable first, backfilled every row, then locked it to NOT NULL once every row had a real value.

Comment on lines +164 to +172
5. **Assuming, not yet confirmed: the `TransducerObservation` (76,725
rows) and `TransducerObservationBlock` (108 rows) rows with
`release_status='provisional'` become `release_level='pending'`,**
migrated in the same pass as every other table rather than held back
separately. Based on the evidence so far (every one of these rows also
has `data_maturity='provisional'`, never `approved`; `docs/
hydrograph-correction-publish.md` describes "publishing as provisional"
as a deliberate operator choice distinct from `public`) — needs real
sign-off from the team.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that release_status='provisional' has to do with review_state, not release_level. I'd assume that the transducer data should have a 'public' release_level, though I'd check with others on that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rows currently have both release_status='provisional' and data_maturity='provisional'. If review_state becomes provisional for them, that matches the existing data_maturity value. For release_level (the visibility axis), we proposed pending based on the our discussion, but happy to change it to public if the team agrees that's the better call.

@jirhiker

Copy link
Copy Markdown
Member

@likithabommasani21, regarding the BDD scenario failures: "These scenarios deliberately rewind the real database schema to an old revision (PRE_A1_REVISION, well before this change) to test an old migration in isolation." Maybe it's best to review the scenarios and make sure they are still relevant/valuable.

@likithabommasani21

Copy link
Copy Markdown
Contributor Author

@likithabommasani21, regarding the BDD scenario failures: "These scenarios deliberately rewind the real database schema to an old revision (PRE_A1_REVISION, well before this change) to test an old migration in isolation." Maybe it's best to review the scenarios and make sure they are still relevant/valuable.

The two failing scenarios only test the old migration's isolated replay — seems low-value now, and it'll keep breaking on future shared-mixin changes. Agreed it's worth reviewing, I will bring it up as a separate ticket

@likithabommasani21
likithabommasani21 force-pushed the BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status branch from 8ad9457 to 2d9524f Compare November 18, 2026 22:41
@likithabommasani21
likithabommasani21 marked this pull request as draft November 18, 2026 23:01
@likithabommasani21
likithabommasani21 marked this pull request as ready for review November 18, 2026 23:02

@ksmuczynski ksmuczynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just two comments for consideration.

f"{dict(unaccounted)}"
)

op.alter_column(table, "release_level", nullable=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set pending as the database-level default for release_level.

Currently, only SQLAlchemy sets this default, so any raw SQL INSERT that omits release_level will violate the NOT NULL constraint. This is why tests/features/environment.py required updates in this PR, and our manual SQL scripts will run into the same failure.

To fix this, update the migration line to:

op.alter_column(
    table, "release_level", nullable=False, server_default="pending"
)

I'd also add server_default="pending" to release_level in ReleaseMixin.

The default should go in alter_column after the backfill. If we set it in add_column, all existing rows become pending immediately, and the migration won't catch any unmapped release_status values.

Comment on lines +140 to +152
for release_status, release_level in (
("public", "public"),
("private", "private"),
("draft", "pending"),
("provisional", "pending"),
):
connection.execute(
sa.text(
f'UPDATE "{table}" SET release_level = :release_level '
f"WHERE release_status = :release_status"
),
{"release_status": release_status, "release_level": release_level},
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a follow-up ticket (linked here before merging) to re-run this backfill when the readers switch over to release_level.

Right now, every write path only updates release_status, so release_level won’t stay in sync for any rows created or modified after this migration runs:

  • Well inventory importer: creates public wells with release_level = 'pending'.
  • Water level importer and hydrograph publish: create observations with release_level = 'pending', regardless of the release_status they set.
  • PATCH routes: update release_status without touching release_level, so a record changed from public to private keeps release_level = 'public'.

Since nothing reads release_level yet, merging this won’t break anything. However, once views and filters switch to release_level, records created or made public after this migration will be missing from public views, while records made private after it will still appear in them.

To keep them aligned, the migration that switches the readers over should also re-run this backfill so release_level matches release_status when the switch happens.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this is safe to merge as-is since nothing reads release_level yet, but opening a follow-up ticket to re-run the backfill when readers switch over

@jacob-a-brown jacob-a-brown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there views (materialized or otherwise) that depend on release_status? If so should those get alembic-migrated here, too?

@likithabommasani21

Copy link
Copy Markdown
Contributor Author

Are there views (materialized or otherwise) that depend on release_status? If so should those get alembic-migrated here, too?

Updating those views/queries to actually use release_level is tracked separately in [1595], along with a re-backfill step before that cutover.

likithabommasani21 and others added 7 commits November 23, 2026 10:14
…al rename

73d27e78571a and 7480e4ee69dc (BDMS-1554, already merged to staging)
both branched off the same parent, creating two alembic heads. Chains
this migration after 7480e4ee69dc instead, and swaps
thing_geologic_formation_association for its new name,
stratigraphic_interval, since that table no longer exists under the
old one by the time this migration runs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@likithabommasani21
likithabommasani21 force-pushed the BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status branch from f612e47 to da3781d Compare November 23, 2026 18:15
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

✅ 82.03% total — gate is 75%.

Coverage for the Python files changed in this PR
Name Stmts Miss Cover Missing
core/enums.py 63 0 100%
db/base.py 55 2 96% 174, 191
TOTAL 118 2 98%

@github-actions

Copy link
Copy Markdown
Contributor

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
ocotillo-automated-ingestion View in Cloud Nov 23, 2026 at 06:19 PM (UTC)

@likithabommasani21
likithabommasani21 merged commit 8853557 into staging Nov 23, 2026
12 checks passed
@likithabommasani21
likithabommasani21 deleted the BDMS-1382-1-2-split-release-status-into-release-level-and-provisional-status branch November 23, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants